package com.day03;

import java.util.Random;
import java.util.Scanner;

//范围取值万能公式:你要获取一个min到max之间的随机整数
//如:8到88,88就是max,8是min
//int num=r.nextInt(max-min+1)+min
public class Demo10 {
    public static void main(String[] args) {
        /*Random r=new Random();
        for (int i = 1; i <=10 ; i++) {
            int num=r.nextInt(10)+1;
            System.out.println(num);
        }*/

        /*Random r=new Random();
        int num=r.nextInt(100)+1;
        Scanner sc=new Scanner(System.in);

        while (true){
            System.out.println("请猜一个数(1-100):");
            int cai=sc.nextInt();

            if (cai<1||cai>100){
                System.out.println("错误,请重新输入!");
            }else if (cai>num){
                System.out.println("猜大了");
            }else if (cai<num){
                System.out.println("猜小了");
            }else{
                System.out.println("猜对了");
                break;
            }
        }*/

        Random r=new Random();
        int num=r.nextInt(100)+1;
        Scanner sc=new Scanner(System.in);

        while(true){
            System.out.println("请猜一个数(1-100):");
            int guessNum=sc.nextInt();

            if (guessNum<1||guessNum>100){
                System.out.println("错误,请重新输入!");
            }else if (guessNum<num){
                System.out.println("猜小了");
            }else if (guessNum>num){
                System.out.println("猜大了");
            }else{
                System.out.println("猜对了");
                break;
            }
        }

    }
}
